package cn.clj;

/**
 * 读取代码块，按行返回字符串
 * 在编译的时候，确定哪些是有问题的
 * */
public class CljLinesFromString {
    private final String[] lines;
    private int index = 0;


    public CljLinesFromString(String code) {
        this.lines = code.split("\r?\n");
    }

    /**
     * 读取下一行
     * */
    public String readLine() {
        if (this.index < this.lines.length)
        {
            String s = this.lines[this.index];
            this.index++;
            return s;
        }
        return null;
    }

    /**
     * 清空数组 lines， 重置 index = 0
     * */
    public void close() {
        clear();
        this.index = 0;
    }

    private void clear()
    {
        for (int i = 0; i < this.lines.length; i++)
        {
            this.lines[i] = null;
        }
    }
}
